@@ -72,25 +72,12 @@ public class PrinterSettingActivity extends BaseActivity implements PrinterSetti |
||
72 | 72 |
bluetoothStatusText.setText(R.string.bt_is_disabled); |
73 | 73 |
} |
74 | 74 |
|
75 |
- @Override |
|
76 |
- public void onPrinterOk() { |
|
77 |
- printerStatusText.setText(R.string.printer_is_ok); |
|
78 |
- } |
|
79 | 75 |
|
80 | 76 |
@Override |
81 |
- public void onPrinterError(String error) { |
|
82 |
- printerStatusText.setText(error); |
|
77 |
+ public void onPrinterStatusFetched(String msg) { |
|
78 |
+ printerStatusText.setText(msg); |
|
83 | 79 |
} |
84 | 80 |
|
85 |
- @Override |
|
86 |
- public void onPrinterConnected() { |
|
87 |
- showToast(getString(R.string.printer_is_connected)); |
|
88 |
- } |
|
89 |
- |
|
90 |
- @Override |
|
91 |
- public void onPrinterDisconnected() { |
|
92 |
- showToast(getString(R.string.printer_is_disconnected)); |
|
93 |
- } |
|
94 | 81 |
|
95 | 82 |
@Override |
96 | 83 |
public void onNewDeviceDiscovered(BluetoothDevice device) { |
@@ -99,11 +86,6 @@ public class PrinterSettingActivity extends BaseActivity implements PrinterSetti |
||
99 | 86 |
|
100 | 87 |
|
101 | 88 |
@Override |
102 |
- public void onPrinterTestPageFail() { |
|
103 |
- |
|
104 |
- } |
|
105 |
- |
|
106 |
- @Override |
|
107 | 89 |
public void onPairedDeviceDiscovered(List<BluetoothDevice> devices) { |
108 | 90 |
if(devices==null|| devices.size()==0){ |
109 | 91 |
return; |
@@ -119,6 +101,7 @@ public class PrinterSettingActivity extends BaseActivity implements PrinterSetti |
||
119 | 101 |
|
120 | 102 |
@OnClick(R.id.tv_printer_status) |
121 | 103 |
void checkStatus(){ |
104 |
+ showToast(getString(R.string.query_processing)); |
|
122 | 105 |
presenter.queryPrinterStatus(); |
123 | 106 |
} |
124 | 107 |
|
@@ -25,12 +25,8 @@ public class PrinterSettingContract { |
||
25 | 25 |
public interface View{ |
26 | 26 |
void onBluetoothEnabled(); |
27 | 27 |
void onBluetoothDisabled(); |
28 |
- void onPrinterOk(); |
|
29 |
- void onPrinterError(String error); |
|
30 |
- void onPrinterConnected(); |
|
31 |
- void onPrinterDisconnected(); |
|
28 |
+ void onPrinterStatusFetched(String status); |
|
32 | 29 |
void onNewDeviceDiscovered(BluetoothDevice device); |
33 |
- void onPrinterTestPageFail(); |
|
34 | 30 |
void onPairedDeviceDiscovered(List<BluetoothDevice> devices); |
35 | 31 |
void showToast(String msg); |
36 | 32 |
} |
@@ -42,13 +42,13 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter |
||
42 | 42 |
class PrinterServiceConnection implements ServiceConnection { |
43 | 43 |
@Override |
44 | 44 |
public void onServiceDisconnected(ComponentName name) { |
45 |
- Log.i("czy", "onServiceDisconnected() called"); |
|
45 |
+ Log.i("czy111", "onServiceDisconnected() called"); |
|
46 | 46 |
mGpService = null; |
47 | 47 |
} |
48 | 48 |
|
49 | 49 |
@Override |
50 | 50 |
public void onServiceConnected(ComponentName name, IBinder service) { |
51 |
- Log.i("czy", "onServiceConnected() called"); |
|
51 |
+ Log.i("czy111", "onServiceConnected() called"); |
|
52 | 52 |
mGpService = GpService.Stub.asInterface(service); |
53 | 53 |
} |
54 | 54 |
} |
@@ -67,7 +67,6 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter |
||
67 | 67 |
if(queryBluetoothStatus()){ |
68 | 68 |
view.onBluetoothEnabled(); |
69 | 69 |
view.onPairedDeviceDiscovered(queryPairedDevices()); |
70 |
- view.showToast(context.getString(R.string.query_processing)); |
|
71 | 70 |
discoverNewDevices(); |
72 | 71 |
|
73 | 72 |
}else{ |
@@ -88,8 +87,7 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter |
||
88 | 87 |
@Override |
89 | 88 |
public void queryPrinterStatus() { |
90 | 89 |
try { |
91 |
- |
|
92 |
- int status = mGpService.queryPrinterStatus(0, 5000); |
|
90 |
+ int status = mGpService.queryPrinterStatus(0, 10000); |
|
93 | 91 |
String str = new String(); |
94 | 92 |
if (status == GpCom.STATE_NO_ERR) { |
95 | 93 |
str = "打印机正常"; |
@@ -111,11 +109,10 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter |
||
111 | 109 |
str += "查询超时"; |
112 | 110 |
} |
113 | 111 |
} |
114 |
- view.showToast( "打印机:" + " 状态:" + str); |
|
115 |
- view.onPrinterError(str); |
|
112 |
+ view.onPrinterStatusFetched(str); |
|
116 | 113 |
|
117 |
- } catch (RemoteException e1) { |
|
118 |
- e1.printStackTrace(); |
|
114 |
+ } catch (Exception e1) { |
|
115 |
+ view.showToast(context.getString(R.string.printer_status_query_fail)); |
|
119 | 116 |
} |
120 | 117 |
} |
121 | 118 |
|
@@ -128,8 +125,7 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter |
||
128 | 125 |
if (r != GpCom.ERROR_CODE.SUCCESS) { |
129 | 126 |
view.showToast( GpCom.getErrorText(r)); |
130 | 127 |
} |
131 |
- } catch (RemoteException e1) { |
|
132 |
- // TODO Auto-generated catch block |
|
128 |
+ } catch (Exception e1) { |
|
133 | 129 |
e1.printStackTrace(); |
134 | 130 |
} |
135 | 131 |
} |
@@ -166,11 +162,15 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter |
||
166 | 162 |
|
167 | 163 |
@Override |
168 | 164 |
public void connectPrinter(BluetoothDevice device) { |
165 |
+ if(mGpService==null){ |
|
166 |
+ view.showToast(context.getString(R.string.printer_service_boot_fail)); |
|
167 |
+ return; |
|
168 |
+ } |
|
169 | 169 |
try { |
170 | 170 |
int code = mGpService.openPort(0, PortParameters.BLUETOOTH, device.getAddress(), 0); |
171 |
- LogHelper.d("czy","open port return code ="+code); |
|
172 |
- } catch (RemoteException e) { |
|
173 |
- e.printStackTrace(); |
|
171 |
+ LogHelper.d("czy111","open port return code ="+code); |
|
172 |
+ } catch (Exception e) { |
|
173 |
+ view.showToast(context.getString(R.string.printer_port_open_fail)); |
|
174 | 174 |
} |
175 | 175 |
} |
176 | 176 |
|
@@ -226,15 +226,15 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter |
||
226 | 226 |
if (GpCom.ACTION_CONNECT_STATUS.equals(intent.getAction())) { |
227 | 227 |
int type = intent.getIntExtra(GpPrintService.CONNECT_STATUS, 0); |
228 | 228 |
int id = intent.getIntExtra(GpPrintService.PRINTER_ID, 0); |
229 |
- Log.d("czy", "connect status " + type); |
|
229 |
+ Log.d("czy111", "connect status " + type); |
|
230 | 230 |
if (type == GpDevice.STATE_CONNECTING) { |
231 |
- |
|
231 |
+ view.onPrinterStatusFetched(context.getString(R.string.connecting)); |
|
232 | 232 |
} else if (type == GpDevice.STATE_NONE) { |
233 | 233 |
|
234 | 234 |
} else if (type == GpDevice.STATE_VALID_PRINTER) { |
235 |
- |
|
235 |
+ view.onPrinterStatusFetched(context.getString(R.string.printer_is_connected)); |
|
236 | 236 |
} else if (type == GpDevice.STATE_INVALID_PRINTER) { |
237 |
- |
|
237 |
+ view.onPrinterStatusFetched(context.getString(R.string.printer_is_disconnected)); |
|
238 | 238 |
} |
239 | 239 |
} |
240 | 240 |
} |
@@ -20,6 +20,7 @@ import java.util.ArrayList; |
||
20 | 20 |
import java.util.Vector; |
21 | 21 |
|
22 | 22 |
import ai.pai.lensman.App; |
23 |
+import ai.pai.lensman.R; |
|
23 | 24 |
import ai.pai.lensman.bean.PhotoBean; |
24 | 25 |
import ai.pai.lensman.bean.SessionBean; |
25 | 26 |
import ai.pai.lensman.db.DBService; |
@@ -141,8 +142,8 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
141 | 142 |
if (r != GpCom.ERROR_CODE.SUCCESS) { |
142 | 143 |
sessionView.showToast( GpCom.getErrorText(r)); |
143 | 144 |
} |
144 |
- } catch (RemoteException e) { |
|
145 |
- e.printStackTrace(); |
|
145 |
+ } catch (Exception e) { |
|
146 |
+ sessionView.showToast(App.getAppContext().getString(R.string.go_check_printer)); |
|
146 | 147 |
} |
147 | 148 |
} |
148 | 149 |
|
@@ -93,7 +93,7 @@ |
||
93 | 93 |
android:id="@+id/tv_printer_status" |
94 | 94 |
android:layout_width="wrap_content" |
95 | 95 |
android:layout_height="wrap_content" |
96 |
- android:text="@string/query_processing" |
|
96 |
+ android:text="@string/click_to_query" |
|
97 | 97 |
android:textColor="@color/dark_grey" |
98 | 98 |
android:textSize="16sp" /> |
99 | 99 |
</LinearLayout> |
@@ -100,4 +100,14 @@ |
||
100 | 100 |
<string name="click_to_connect">点击连接</string> |
101 | 101 |
|
102 | 102 |
<string name="connecting">尝试连接中</string> |
103 |
+ |
|
104 |
+ <string name="click_to_query">点击查询打印机状态</string> |
|
105 |
+ |
|
106 |
+ <string name="go_check_printer">请检查打印机</string> |
|
107 |
+ |
|
108 |
+ <string name="printer_port_open_fail">打印机端口打开失败</string> |
|
109 |
+ |
|
110 |
+ <string name="printer_status_query_fail">打印机状态查询失败</string> |
|
111 |
+ |
|
112 |
+ <string name="printer_service_boot_fail">打印机服务连接失败,请退出应用重试</string> |
|
103 | 113 |
</resources> |